# 创建ppt与基本操作
# pip install python-pptx

import collections
import collections.abc

from pptx.util import Pt

from pptx import Presentation


def base_ppt1():
    # 创建 PPT
    ppt = Presentation()
    slide = ppt.slides.add_slide(ppt.slide_layouts[1])      # 创建幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[2])      # 创建幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[3])      # 创建幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[4])      # 创建幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[5])      # 创建幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[6])      # 创建幻灯片

    ppt.save('../02.py_pptFile/01.创建ppt.pptx')


def base_ppt2():
    ppt = Presentation()

    # 模板一   ------------------------------------------------------------------------------------------
    slide = ppt.slides.add_slide(ppt.slide_layouts[1])
    # 获取内容框
    shapes = slide.shapes

    title = shapes.title
    title.text = 'This is Python Title!'

    content = shapes.placeholders[1]
    content.text = 'Content Info!'

    # 模板二   ------------------------------------------------------------------------------------------
    slide2 = ppt.slides.add_slide(ppt.slide_layouts[1])
    shapes = slide2.shapes
    content = shapes.placeholders[1]
    content.text_frame.text = 'add paragraph2'

    # 模板三   ------------------------------------------------------------------------------------------
    # 增加新段落的方式
    slide3 = ppt.slides.add_slide(ppt.slide_layouts[1])
    # 获取内容框
    shapes = slide3.shapes

    content = shapes.placeholders[1]
    content.text = 'Content Info22!'

    tf = content.text_frame
    p1 = tf.add_paragraph()
    p1.level = 1
    p1.text = 'add paragraph1'

    content.text_frame.add_paragraph().text = 'add paragraph2'

    p2 = tf.add_paragraph()
    p2.level = 2
    p2.text = 'add paragraph3'

    p3 = tf.add_paragraph()
    p3.level = 3
    p3.text = 'add paragraph4'

    p4 = tf.add_paragraph()
    p4.text = 'add paragraph5'
    p4.font.bold = True
    p4.font.size = Pt(30)

    # 模板四   ------------------------------------------------------------------------------------------
    slide4 = ppt.slides.add_slide(ppt.slide_layouts[6])
    left = top = width = height = Pt(300)
    text_box = slide4.shapes.add_textbox(left, top, width, height)    # 设置文本框的外边距

    tf = text_box.text_frame
    tf.text = '这是一个文本框内容！'
    p5 = tf.add_paragraph()
    p5.text = 'add paragraph6'

    ppt.save('../02.py_pptFile/01_1.添加ppt内容.pptx')


if __name__ == '__main__':
    # base_ppt1()
    base_ppt2()
